<?php

namespace app\api\controller;

use app\admin\model\CooperateBrand;
use app\admin\model\CooperateForm;
use app\api\model\Feedback;
use app\common\controller\Api;
use think\Validate;

/**
 * 合作接口
 */
class Cooperate extends Api
{
    protected $noNeedLogin = ['cooperateintro','cooperatebrand'];
    protected $noNeedRight = ['*'];

    //合作品牌
    public function cooperatebrand()
    {
        $list = CooperateBrand::order('weigh desc')->field('image')->select();
        $this->success('请求成功',$list);
    }

    //招商加盟计划介绍
    public function  cooperateintro()
    {
        $name = input('name','cooperate_intro');

        $value = \app\common\model\Config::get(['name'=>$name])->value;

        $this->success('请求成功',$value);
    }

    //合作表单提交
    public function cooperateform()
    {
        $model = new CooperateForm();

        $data = [
            'user_id'=>$this->auth->id,
            'realname'=>input('realname',''),
            'mobile'=>input('mobile','')
        ];
        if (empty($data['realname']))$this->error('请输入姓名');
        if (empty($data['mobile']))$this->error('请输入手机号');
        if (!Validate::regex($data['mobile'], "^1\d{10}$")) {
            $this->error('手机号格式错误');
        }
        $res = $model->save($data);
        if ($res){
            $this->success('提交成功');
        } else {
            $this->error('提交失败');
        }
    }
}
